<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/admin/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>评价管理</el-breadcrumb-item>
      <el-breadcrumb-item>评价图表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-alert title="选择餐厅查看评价图表" type="info" show-icon :closable="false">
      </el-alert>
      <el-table :data="merchantList" stripe border>
        <el-table-column type="index" label="序号"></el-table-column>
        <el-table-column label="商家名" prop="rnickname"></el-table-column>
        <el-table-column label="用户名" prop="rname"></el-table-column>
        <el-table-column label="操作" width="250px">
          <template slot-scope="scope">
            <el-button type="success" size="mini" @click="showReport1(scope.row.rid)">图表1</el-button>
            <el-button type="success" size="mini" @click="showReport2(scope.row.rid)">图表2</el-button>
            <el-button type="success" size="mini" @click="showReport3(scope.row.rid)">图表3</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total" background>
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'Report',
  data () {
    return {
      merchantList: [],
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 5
      },
      total: 0
    }
  },
  created () {
    this.getMerchantList()
  },
  methods: {
    async getMerchantList () {
      const { data: result } = await this.$axios.get('/admin/restaurant/query', { params: this.queryInfo })
      if (result.status !== 2000) {
        return this.$message.error('获取商家列表失败')
      }
      this.merchantList = result.data.restaurants
      this.total = result.data.total
    },
    // 当每页显示的最大数据条数发生变化时，调用该函数
    handleSizeChange (newSize) {
      this.queryInfo.pagesize = newSize
      this.getMerchantList()
    },
    // 当当前页数发生变化时，调用该函数
    handleCurrentChange (newPage) {
      this.queryInfo.pagenum = newPage
      this.getMerchantList()
    },
    showReport1 (rid) {
      this.$router.push({ name: 'AdminShowReport1', params: { rid: rid } })
    },
    showReport2 (rid) {
      this.$router.push({ name: 'AdminShowReport2', params: { rid: rid } })
    },
    showReport3 (rid) {
      this.$router.push({ name: 'AdminShowReport3', params: { rid: rid } })
    }
  }
}
</script>

<style scoped>

</style>
